$(function(){


//图片异步上传
$('#imag_upload').on('submit',(function(e) {
        e.preventDefault();
        var formData = new FormData(this);

        $.ajax({
            type:'POST',
            url: $(this).attr('action'),
            data:formData,
            cache:false,
            contentType: false,
            processData: false,
            success:function(data){

            	location.reload()
				//alert("上传成功！")


				$(".confrim").hide()
            },
            error: function(data){
                alert("上传失败！")
				$(".confrim #close").trigger("click")
            }
        });
}));

//异步删除图片
$('#head_del').click(function(){

	$.ajax({
            type:'GET',
            url: "del/图片路径名",
            success:function(data){
            	location.reload()
            },
            error: function(data){
            }
        });

})



//表单验证
$(".user_inner form").submit(function(e){
	
	if($(this).attr("class") != "indepent"){

	var pass = true;
	$(".check").each(function(){
		var input = $(this);
		if(!rule(input)){
			pass = false
			}
	})

	if(!pass){
		e.preventDefault();
	}
	
	}
	
});


$(".user_inner form .check").each(function(){
		var input = $(this);
		input.blur(function(){
			rule(input)
	})
})


function rule(input){
	var swc = true;
			len = input.val().length
			txt = input.parent().find("small")
			
			input.removeClass("attention")
			txt.remove()
				
			if(len === 0){
				input.addClass("attention")
				swc = false
				if(txt.length<1){
					input.after("<small class='red'>　此处不得为空！</small>")
				}
				
			}else if(input.attr("id") === "password_b"){
				
				//密码重复表单验证
				var a = $("#password_a").val()
				var b = $("#password_b").val()
				if(a!=b){
					swc = false
					input.after("<small class='red'>　两次输入的密码不一致！</small>")
				}
				
			}else{
				
			}
	return swc
}

})